package com.stage.common;

import java.util.List;

public class MathUtil {
	public static double max(Double[] seq) {
		double max = 0.0;
		for (int i = seq.length - 1; i >= 0; i--) {
			max = Math.max(max, seq[i]);
		}
		return max;
	}
	
	public static double min(Double[] seq) {
		double min = 0.0;
		for (int i = seq.length - 1; i >= 0; i--) {
			min = Math.min(min, seq[i]);
		}
		return min;
	}
	
	public static double mean(Integer[] seq) {
		double mean = 0.0;
		double sum = 0.0;
		for (int i = seq.length - 1; i >= 0; i--) {
			sum += seq[i];
		}
		mean = sum/seq.length;
		return mean;
	}

	public static <E> StringBuffer array2String(List<E> list) {
		StringBuffer sb = null;
		if (list != null && !list.isEmpty()) {
			sb = new StringBuffer();
			for (E element : list) {
				sb.append(element.toString()).append(" ");
			}
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb;
	}
	
	public static Double std(Double[] seq) {
		double std = 0.0;
		double sum = 0.0;
		double square = 0.0;
		for (int i = 0; i < seq.length; i++){
			sum += seq[i];
			square += seq[i]*seq[i];
		}
		std = Math.sqrt((square - sum*sum/seq.length)/(seq.length-1));
		
		return std;
	}


	
}